package com.wu.project.admin.api;

import com.wu.project.admin.annotations.Authorization;
import com.wu.project.admin.annotations.Log;
import com.wu.project.admin.component.JsonResult;
import com.wu.project.admin.entity.UpdateRoleVO;
import com.wu.project.admin.service.AuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xuan
 */
@RestController
@RequestMapping("/authority")
public class AuthorityApi {

    @Autowired
    AuthorityService authorityService;

    @Authorization
    @Log(name = "获取权限管理下的用户列表", isOpen = true)
    @GetMapping("/user/list")
    public JsonResult userList() {
        return authorityService.getAuthUserList();
    }

    @Authorization
    @Log(name = "获取权限管理下的用户菜单",isOpen = true)
    @GetMapping("/user/menu")
    public JsonResult userMenu(String userId) {
        return authorityService.getAuthorityByUserId(userId);
    }

    @Authorization
    @Log(name = "获取权限管理下的角色列表",isOpen = true)
    @GetMapping("/role/list")
    public JsonResult roleList() {
        return authorityService.getRoleList();
    }

    @Authorization
    @Log(name = "获取角色下的对应菜单")
    @GetMapping("/role/menu")
    public JsonResult roleMenu(Long roleId) {
        return authorityService.getRoleMenu(roleId);
    }

    @Authorization
    @Log(name = "删除角色一下的某一个菜单")
    @PostMapping("/role/delete")
    public JsonResult deleteMenu(Long roleMenuId) {
        return authorityService.deleteRoleMenu(roleMenuId);
    }

    @Authorization
    @Log(name = "更新用户角色")
    @PostMapping("/role/update")
    public JsonResult updateRole(@RequestBody UpdateRoleVO updateRoleVO) {
        return authorityService.updateRole(updateRoleVO);
    }
}
